﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached.Tx
{
    /// <summary>
    /// We assume null is not a valid value.
    /// </summary>
    internal sealed class GetCasOp<T> : ReadOnlyOp
    {
        [System.Diagnostics.DebuggerHidden]
        public GetCasOp(ICacheAdvanced real, ICacheAdvanced temp, string key)
            : base(real, temp, key)
        {
        }

        public override string Name
        {
            [System.Diagnostics.DebuggerHidden]
            get { return "GetCas:" + Key; }
        }

        public override object Execute()
        {
            // get the current Volatile value, if set in transaction, or the Committed one
            CasValue<T> current = ((ICacheAdvanced)Temp).Get<T>(Key);
            if (current != null)// either value not there or invalid type
                return current;
            return ((ICacheAdvanced)Store).Get<T>(Key);
        }
    }
}